#!/bin/bash
#
# helper script for building pdf docs
#

DOCNAME=$1

cat $DOCNAME/$DOCNAME.sgml | sed -e 's+DOCTYPE book+DOCTYPE article+ig' \
-e 's+common/help.sgml+common/help-article.sgml+ig' \
-e 's+<bookinfo+<artheader+ig' \
-e 's+</bookinfo>+</artheader>+ig' \
-e 's+<partintro>++ig' \
-e 's+</partintro>++ig' |\
sed -e 's+<book+<article+ig' \
-e 's+<part+<section+ig' \
-e 's+<chapter+<section+ig' \
-e 's+</book+</article+ig' \
-e 's+</part>+</section>+ig' \
-e 's+</chapter>+</section>+ig' \
> $DOCNAME/$DOCNAME-article.sgml
mkdir -p $DOCNAME/pdf/pics
cp $DOCNAME/html/pics/*.png $DOCNAME/pdf/pics 2>/dev/null || true
(cd $DOCNAME/pdf; openjade -d ../../stylesheet.dsl\#print -t tex \
-o $DOCNAME-article.tex ../$DOCNAME-article.sgml; \
cat $DOCNAME-article.tex \
| ../../../../../script/change-tex-pl-entities2.sh > \
polish-ent.tex.tmp; mv polish-ent.tex.tmp $DOCNAME-article.tex; \
pdfjadetex $DOCNAME-article.tex 2>&1 >/dev/null; \
pdfjadetex $DOCNAME-article.tex 2>&1 >/dev/null; \
pdfjadetex $DOCNAME-article.tex 2>&1 >/dev/null)

mkdir -p ./pdf/
cp $DOCNAME/pdf/*.pdf ./pdf/
